package com.lin.operatorlogrecord.strategy;

import com.lin.operatorlogrecord.content.ObjectUpdateLogUtil;
import com.lin.operatorlogrecord.exception.OperatorLogException;
import com.lin.operatorlogrecord.unit.OperatorLogUtil;

import java.util.List;

/**
 * @Author: chenghao.lin
 * @Date: 2023/09/25
 * @Description: 更新生成变更内容模板
 */
public class UpdateOperatorLogStrategy implements IOperateLogStrategy{
    @Override
    public String getOperatorContent(Object requestObj, Class<?>[] tableEntity, String operatorObjId) {
        ObjectUpdateLogUtil objectUpdateLogUtil = new ObjectUpdateLogUtil();
        List<String> result;
        try {
            Object oldObject = OperatorLogUtil.getObj(requestObj.getClass(), operatorObjId, tableEntity[0]);
            // 生成变更日志
            result = objectUpdateLogUtil.generatorChangeLog(oldObject, oldObject.getClass(), requestObj, requestObj.getClass(),
                    OperatorLogUtil.getObjectTypeEnum(tableEntity[0]).getName());
        } catch (Exception e) {
            throw new OperatorLogException("生成更新对象操作日志失败", e);
        }
        return result.get(0);
    }
}
